<template>
  <div class="app-container">
    <el-form :inline="true" :model="listQuery" @submit.native.prevent>
      <el-form-item label="用户名">
        <el-input v-model="listQuery.q_memberName" maxlength="50" size="small" class="filter-item" />
      </el-form-item>
      <el-form-item label="是否打款">
        <el-select v-model="listQuery.q_state" size="small" placeholder="请选择">
          <el-option v-for="item in states" :label="item.name" :key="item.value" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="small" type="primary" @click="check">查询</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="reset">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="button-table-margin">
      <el-button size="small" type="primary" @click="updatemoneystate"
        v-permission="['admin/sale/saleapplymoney1/updatemoneystate']">打款</el-button>
    </div>
    <el-table ref="singleTable" :data="dataList" border fit v-loading="listLoading" highlight-current-row
      style="width: 100%" @current-change="handleCurrentChange">
      <el-table-column type="index" align="center" width="50">
      </el-table-column>
      <el-table-column property="memberName" width="150" label="用户姓名"></el-table-column>
      <el-table-column property="state" width="200" label="是否打款">
        <template slot-scope="scope">
          {{ codeBox.YES_NO[scope.row.state] }}
        </template>
      </el-table-column>
      <el-table-column property="bankName" width="200" label="收款人姓名"></el-table-column>
      <el-table-column property="certificateCode" width="200" label="证件号码" show-overflow-tooltip></el-table-column>
      <el-table-column property="bankType" width="200" label="开户行" show-overflow-tooltip></el-table-column>
      <el-table-column property="bankCode" width="200" label="银行卡号" show-overflow-tooltip></el-table-column>
      <el-table-column property="bankAdd" width="200" label="开户行地址" show-overflow-tooltip></el-table-column>
      <el-table-column property="money" width="200" label="金额"></el-table-column>
      <el-table-column property="createTime" width="200" label="取款时间"></el-table-column>
      <el-table-column property="updateName" width="200" label="汇款人姓名"></el-table-column>
      <el-table-column property="updateTime" width="200" label="汇款时间"></el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      @pagination="getList" />
  </div>
</template>
<script>
  import {
    fetchSaleApplyMoneyList,
    updatemoneystate
  } from '@/api/sale'
  import {
    getCodeManager,
    codeToArray
  } from '@/api/all'
  import Pagination from '@/components/Pagination'
  import {
    Message
  } from 'element-ui'
  export default {
    name: 'saleapplymoneylist',
    components: {
      Pagination
    },
    data() {
      return {
        dataList: [],
        states: [],
        total: 0,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 20,
          q_state: '',
          q_memberName: ''
        },
        currentRow: null
      }
    },
    created() {
      getCodeManager('YES_NO', () => {
        this.states = codeToArray('YES_NO');
      })
      this.getList()
    },
    methods: {
      handleCurrentChange(val) {
        // 选中当前行数据
        this.currentRow = val
      },
      // 获取列表数据
      getList() {
        this.listLoading = true
        fetchSaleApplyMoneyList(this.listQuery).then(response => {
          this.dataList = response.data.rows
          this.total = response.data.total
          this.listLoading = false
          console.log(this.dataList)
        })
      },
      handleFilter() {
        this.listQuery.page = 1
        this.getList()
      },
      check() {
        this.getList()
      },
      reset() {
        this.listQuery = {
          page: 1,
          limit: 20,
          q_state: '',
          q_memberName: ''
        }
        this.getList()
      },
      updatemoneystate() {
        if (!this.currentRow) {
          Message.error('请选择操作行。')
          return;
        };
        if (this.currentRow.state != 0) {
          Message.error('已经打款，请勿重复操作。')
          return;
        }
        this.$confirm('确定打款吗？', '提示', {
          onfirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          updatemoneystate({
            id: this.currentRow.id
          }).then(res => {
            if (res.data.success) {
              this.$message({
                type: 'success',
                message: '打款成功!'
              });
              this.getList()
            } else {
              this.$message({
                type: 'error',
                message: res.data.message
              });
            }
          })
        })
      }
    }
  }
</script>
<style scoped>
  .filter-container .el-col-6 {
    margin-bottom: 15px;
  }

  .filter-item {
    margin-bottom: 0
  }

  /deep/ .filter-container label {
    font-size: 14px;
    font-weight: 500;
    margin-right: 10px;
  }
</style>
